package com.api;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: lxf
 * Date: 2018/1/8
 * Time: 16:56
 * To change this template use Editor | File and Code Templates.
 */
public class ApiResultUtil {

    private ApiResultUtil() {
    }

    /**
     * 构造一个包含数据的成功结果
     *
     * @param data 数据data部分
     * @return
     */
    public static ApiSuccResult newSuccResult(Object data) {
        ApiSuccResult result = new ApiSuccResult();
        result.setData(data);
        return result;
    }

    /**
     * 构造一个成功结果
     *
     * @param data 数据data部分
     * @return
     */
    public static <T> ApiResult newListResult(List<T> data) {
        ApiResult result;
        if (data == null || data.isEmpty()) {
            result = new ApiEmptyResult();
            result.setData(new ArrayList<T>());
        } else {
            result = new ApiSuccResult();
            result.setData(data);
        }

        return result;
    }

    /**
     * 提示信息
     *
     * @param msg
     * @return
     */
    public static ApiTipResult newTipResult(String msg) {
        ApiTipResult result = new ApiTipResult(msg);
        result.setData("");
        return result;
    }


}
